﻿<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/OpenDelib.Master" CodeBehind="GestionVotes.aspx.vb" Inherits="OpenDelib.GestionVotes" %>
<%@ Register TagPrefix="cc1" Namespace="Odyssee.WebControles" Assembly="Odyssee.WebControles" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">    
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="toolbar" runat="server">   
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="content" runat="server">
    <style type="text/css">
        .grid th, .gridheader, .selectiongrid, .gridpager, .selectiongridpager {
            font-weight:normal;
            height: 24px;
            line-height:24px;
            padding:0px;
        }
        .grid th[scope="row"] {
            text-align: right;
            padding-right: 10px;
        }
        .grid tr:hover th[scope="row"] {
            background-color: #244154;
        }
    </style>


    <div style="margin:15px; font-family:'Segoe UI';">

        <div class="divTitle">
            <asp:Label runat="server" Text="Assemblée" CssClass="labelDivTitle" />
        </div>
        <asp:TextBox ID="txtAssemblee" runat="server" TextMode="SingleLine" CssClass="textbox" Style="width:calc(100% - 6px);" Enabled="false" />
        <cc1:AcroGridView ID="gvAssemblees" runat="server" AutoGenerateColumns="false" CssClass="grid" AllowPaging="true" PageSize="10" PagerStyle-CssClass="gridpager" AllowSorting="false" EmptyDataText="" EmptyDataRowStyle-HorizontalAlign="Center" ShowHeaderWhenEmpty="True">
            <Columns>
                <asp:TemplateField HeaderText="" SortExpression="" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false">
                    <ItemTemplate><asp:CheckBox ID="chkSelection" runat="server" Checked="False" Text='<%#Eval("CodeDossier")%>' CssClass="hiddenCheckBox" /></ItemTemplate>
                </asp:TemplateField>
                <cc1:BoundField DataField="CodeDossier" ReadOnly="True" SortExpression="CodeDossier" HeaderText="Code" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false" />
                <cc1:BoundField DataField="Identificateur" ReadOnly="True" SortExpression="Identificateur" HeaderText="Identificateur" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false" />
                <cc1:BoundField DataField="DateAssemblee" ReadOnly="True" SortExpression="DateAssemblee" HeaderText="Date de l'assemblée" DataFormatString="{0:d}" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false" />
                <cc1:BoundField DataField="LieuAssemblee" ReadOnly="True" SortExpression="LieuAssemblee" HeaderText="Lieu de l'assemblée" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false" />
            </Columns>
        </cc1:AcroGridView>

        <div id="lblRapport" runat="server" class="divTitle" style="margin-top:15px;">
            <asp:Label runat="server" Text="Rapport" CssClass="labelDivTitle" />
        </div>
        <asp:TextBox ID="txtRapport" runat="server" TextMode="SingleLine" CssClass="textbox" Style="width:calc(100% - 6px);" Enabled="false" />
        <cc1:AcroGridView ID="gvRapports" runat="server" AutoGenerateColumns="false" CssClass="grid" AllowPaging="true" PageSize="10" PagerStyle-CssClass="gridpager" AllowSorting="false" EmptyDataText="" EmptyDataRowStyle-HorizontalAlign="Center" ShowHeaderWhenEmpty="True">
            <Columns>
                <asp:TemplateField HeaderText="" SortExpression="" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false">
                    <ItemTemplate><asp:CheckBox ID="chkSelection" runat="server" Checked="False" Text='<%#Eval("CodeDossier")%>' CssClass="hiddenCheckBox" /></ItemTemplate>
                </asp:TemplateField>
                <cc1:BoundField DataField="CodeDossier" ReadOnly="True" SortExpression="CodeDossier" HeaderText="Code" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false" />
                <cc1:BoundField DataField="Identificateur" ReadOnly="True" SortExpression="Identificateur" HeaderText="Identificateur" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false" />
            </Columns>
        </cc1:AcroGridView>
        

        <div id="lblVotes" runat="server" class="divTitle" style="margin-top:15px;">
            <asp:Label runat="server" Text="Votes" CssClass="labelDivTitle" />
        </div>
        <asp:Table id="tbVotes" runat="server" class="grid" style="border-collapse:collapse;" border="1" rules="all" cellspacing="0">
        </asp:Table>
    </div>

    <div style="margin:20px; text-align:center;">
        <asp:Button ID="btnPrecedent" CssClass="btn" Text="< Précédent" runat="server" Width="100px" />
        <asp:Button ID="btnSuivant" CssClass="btn" Text="Suivant >" runat="server" Width="100px" />
        <asp:Button ID="btnAnnuler" CssClass="btn" Text="Annuler" runat="server" Width="100px" OnClientClick="return confirm('Êtes-vous sûr de vouloir annuler les votes ?');" />
        <asp:Button ID="btnEnregistrer" CssClass="btn" Text="Enregistrer" runat="server" Width="100px" OnClientClick="return confirm('Êtes-vous sûr de vouloir valider les votes ?');" />
        <asp:Button ID="btnModifier" CssClass="btn" Text="Modifier" runat="server" Width="100px" OnClientClick="return confirm('Êtes-vous sûr de vouloir modifier les votes ?');" />
        <asp:Button ID="btnNouveau" CssClass="btn" Text="Nouveau vote" runat="server" Width="100px" />
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function () {
                $("[id*=gvAssemblees] input[type=checkbox]").bind("click", function () {
                    var isChecked = $(this).is(":checked");
                    if (!isChecked) return;

                    var tv = $("[id*=gvAssemblees]");
                    if (!tv) return;
                    if (tv.length <= 0) return;

                    var chk = $(this);
                    $("input[type=checkbox]", tv).each(function () {
                        if ($(this)[0].id == chk[0].id) return;
                        $(this).prop('checked', false);
                    });
                });

                $("[id*=gvRapports] input[type=checkbox]").bind("click", function () {
                    var isChecked = $(this).is(":checked");
                    if (!isChecked) return;

                    var tv = $("[id*=gvRapports]");
                    if (!tv) return;
                    if (tv.length <= 0) return;

                    var chk = $(this);
                    $("input[type=checkbox]", tv).each(function () {
                        if ($(this)[0].id == chk[0].id) return;
                        $(this).prop('checked', false);
                    });
                });

                $("[id*=tbVotes] input[type=radio]").bind("change", function () {
                    gererContactsPouvoir();

                    // Enable / disable de la combo de pouvoir selon le vote
                    var rbAbsent = $(this).parent().parent().find("td[vote=absent] input[type=radio]");
                    var isChecked = rbAbsent.is(":checked");
                    var cb = rbAbsent.parent().parent().find("select");
                    if (!cb) return;
                    if (cb.length <= 0) return;
                    if (isChecked)
                        cb.removeAttr("disabled");
                    else
                        cb.attr("disabled", "disabled");
                });
            });
        });

        function selectionnerTout(vote) {
            $("[id*=tbVotes] td[vote=" + vote + "] input[type=radio]").prop("checked", true);
        }
        function affecterValeur(cb) {
            var cb = $(cb).parent().find("select");
            if (!cb || !cb.length) return;
            var hidden = $(cb).parent().find("input[type=hidden]");
            if (!hidden || !hidden.length) return;
            affectHiddenSelectedValue(cb[0], hidden[0]);
        }

        function gererContactsPouvoir() {
            // Suppression des contacts non présents des combos de pouvoir
            $("[id*=tbVotes] select").each(function () {
                var cb = this;
                var hidden = $(cb).parent().find("input[type=hidden]");
                var m = membres.slice(0);

                $("[id*=tbVotes] td[vote=absent] input[type=radio]:checked").each(function () {
                    var cle = $(this).parent().parent().find("th").attr("contact");
                    for (var i = m.length - 1; i >= 0; i--) {
                        if (m[i][1] == cle) {
                            m.splice(i, 1);
                            return;
                        }
                    }
                });

                cb.options.length = 0;
                for (var i = 0; i <= m.length - 1; i++) {
                    if (!comboContainsValue(cb, m[i][1])) {
                        addOption(cb, m[i][0], m[i][1]);
                    }
                }
                selectOption(cb, hidden.val());
            });
        }
    </script>

</asp:Content>